package com.wealth.scsj.b_app.view.activity.payment;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.alibaba.fastjson.JSONObject;
import com.jungly.gridpasswordview.GridPasswordView;
import com.wealth.scsj.b_app.R;
import com.wealth.scsj.b_app.base.RetrievePayPwdBase;
import com.wealth.scsj.b_app.bean.BaseBean;
import com.wealth.scsj.b_app.presenter.RetrievePayPwdPresenter;
import com.wealth.scsj.b_app.view.activity.BaseActivity;

import es.dmoral.toasty.Toasty;
import okhttp3.RequestBody;

/**
 *
 * 重置/设置支付密码
 */

public class ResetPaymentPasswordActivity extends BaseActivity implements View.OnClickListener, RetrievePayPwdBase.IView {
    /**
     * 确定
     */
    private Button mBtnEnsure;
    private GridPasswordView mPswView;
    private String smsCode;
    private RetrievePayPwdPresenter presenter;

    @Override
    protected void createView(Bundle savedInstanceState) {
        setContentView(R.layout.activity_reset_payment_password);
        //ScreenAdapterTools.getInstance().loadView((ViewGroup) getWindow().getDecorView());
        //ScreenAdapterTools.getInstance().reset(this);//如果希望android7.0分屏也适配的话,加上这句
        initToolbar();
        setToolbarTitle("设置支付密码");
        hasBack(true);
        smsCode = getIntent().getStringExtra("SmsCode");
        presenter = new RetrievePayPwdPresenter(this);
    }

    @Override
    protected void initView() {

        mBtnEnsure = (Button) findViewById(R.id.btn_ensure);
        mBtnEnsure.setOnClickListener(this);
        mPswView = (GridPasswordView) findViewById(R.id.pswView);
    }

    @Override
    protected void initListener() {
    }

    @Override
    protected void initData() {

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {

            case R.id.btn_ensure:
//                ToastMiddleUtils.ToastMiddle(this,mPswView.getPassWord());
                if(mPswView.getPassWord().length() < 6){
                    Toasty.info(this,"请输入六位支付密码").show();
                    return;
                }
                JSONObject object = new JSONObject();
                object.put("code", smsCode);
                object.put("newPassword", mPswView.getPassWord());
                RequestBody requestBody = RequestBody.create(okhttp3.MediaType
                        .parse("application/json;charset=utf-8"), object.toString());
                presenter.deliverSetNewPayPwdData(requestBody);
                break;

            default:
                break;
        }
    }

    @Override
    public void sendSmsCodeSuccessMsg(String s, BaseBean addDABean) {

    }

    @Override
    public void verifySmsCodeSuccessMsg(String s, BaseBean deleteDABean) {

    }

    @Override
    public void SetNewPayPwdSuccessMsg(String s, BaseBean deleteDABean) {
        Toasty.success(this,s).show();
    }

    @Override
    public void showErrorMsg(String s) {
        Toasty.error(this,s).show();
    }
}
